<template>
  <a-table
           :customRow="setRow"
           :columns="columns"
           :dataSource="goods"
           rowKey="code"
  >
    <template #name="{ record }">
      <a-button type="primary" ghost @click="hide(record)" size="small">添加</a-button>
    </template>

  </a-table>
</template>

<script>
import {ref} from "vue";
import store from "@/store";
import request from "@/utils/request";

export default {
  name: "GoodsDisplayByCode",
  data(){
    return{
      goods:ref(store.getters.getSellGoods),
      columns: [
        {
          title:'',
          dataIndex:'add',
          key:'add',
          align: "center",
          slots: { customRender: "name" }
        },
        {
          title: '编号',
          dataIndex: 'code',
          key: 'code',
        },
        {
          title: '商品名称',
          dataIndex: 'goodsName',
          key: 'goodsName',
        },
        {
          title: '库存',
          dataIndex: 'goodsInventory',
          key: 'goodsInventory',
        }
      ]
    }
  },
  mounted() {
    this.goods=store.getters.getSellGoods
  },
  methods:{
    hide(record){
      request.get("http://localhost:8002/goods/"+record.code).then(res=>{
        store.commit("setData",res.data)
        store.commit("setCode",223)
        this.$router.push("/sms/rounte")
      })
    }
  }
}
</script>

<style scoped>

</style>